package storage

import (
	"gin-base/common/services/storage"

	"github.com/gin-gonic/gin"
)

func Upload(this *gin.Context) {
	fromFile := "file"

	f, h, err := this.Request.FormFile(fromFile)
	defer f.Close()

	if err != nil {
		this.JSON(400, "文件上传失败")
	} else {
		fileName, err := storage.SaveToFile(this.Request, fromFile, h.Filename)
		if err != nil {
			this.JSON(400, "文件上传失败")
		} else {
			this.JSON(200, fileName)

		}
	}
}
